package cn.itcast.travel.web.servlet.comment;

import cn.itcast.travel.domain.comment;
import cn.itcast.travel.service.CommentService;
import cn.itcast.travel.service.impl.CommentServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet(name = "Addcomment", value = "/Addcomment")
public class Addcomment extends HttpServlet {
    CommentService service=new CommentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        comment c=new comment();
        Map mp=request.getParameterMap();
        try {
            BeanUtils.populate(c,mp);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        service.addpin(c);
        ObjectMapper ob=new ObjectMapper();
        ob.writeValue(response.getWriter(),1);
    }
}
